﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Test_LYK.DataAccess;
using Test_LYK.Models;

namespace Test_LYK.Repository
{
    public class PersonRepository
    {
        public bool AddPerson(string name)
        {
            var db = new EatEntities();

            db.Person.Add(new Person() {Name = name});

            return db.SaveChanges()>0;
        }

        public bool ModifyPerson(int id, string name)
        {
            var db = new EatEntities();
            var person = db.Person.FirstOrDefault(s => s.Id == id);
            person.Name = name;
            return db.SaveChanges()>0;
        }

        public List<PersonModel> GetPersonList()
        {
            var db = new EatEntities();

            var personList = db.Person.Select(s=> new PersonModel(){Id=s.Id,Name = s.Name}).ToList();

            return personList;
        }
    }
}